package com.gency.subscribe;

import org.junit.Test;

public class BulidFile {

	
	
	    //@Test
	    public void vip() {
	        String packageName = "com.newzqxq.kabao.entity.activity";
	        String[] tabPrefix = new String[]{"act_"};
	        generateByTables(packageName, tabPrefix, "act_coupon_config"
	        );
	    }
	
//	    @org.junit.Test
	    public void acct() {
	        String packageName = "com.newzqxq.kabao";
	        String[] tabPrefix = new String[]{"acc_"};
	        generateByTables(packageName, tabPrefix, "acc_user_card",
	                "acc_product_sign"
	        );
	    }
//	      @org.junit.Test
//	    public void trade() {
//	        String packageName = "com.newzqxq.kabao.entity.vip";
//	        String[] tabPrefix = new String[]{"vip_", "reg_"};
//	        generateByTables(packageName, tabPrefix, "vip_user_vip"
//	        );
//	    }
	    @Test
	    public void reg() {
	        String packageName = "com.gency.api";
	        String[] tabPrefix = new String[]{"sys_", "reg_" ,"trd_"};
	        generateByTables(packageName, tabPrefix, "trd_sendamount_record");
	    }
	
	
	    private void generateByTables(String packageName, String[] tabPrefix, String... tableNames) {
	
	
	        // 代码生成器
	        com.baomidou.mybatisplus.generator.AutoGenerator autoGenerator = new com.baomidou.mybatisplus.generator.AutoGenerator();
	        // 全局配置
	        com.baomidou.mybatisplus.generator.config.GlobalConfig globalConfig = new com.baomidou.mybatisplus.generator.config.GlobalConfig();
	        // 数据源配置
	        com.baomidou.mybatisplus.generator.config.DataSourceConfig dataSourceConfig = new  com.baomidou.mybatisplus.generator.config.DataSourceConfig();
	        // 程序包配置
	        com.baomidou.mybatisplus.generator.config.PackageConfig packageConfig = new com.baomidou.mybatisplus.generator.config.PackageConfig();
	        // 名称策略配置
	        com.baomidou.mybatisplus.generator.config.StrategyConfig strategyConfig = new com.baomidou.mybatisplus.generator.config.StrategyConfig();
	
	        globalConfig.setActiveRecord(true);
	        globalConfig.setAuthor("马行空");
	        globalConfig.setOutputDir("d:\\codeGen");
	        globalConfig.setFileOverride(true);
	        globalConfig.setEnableCache(false);
	        globalConfig.setBaseResultMap(true);
	
	        dataSourceConfig.setDbType(com.baomidou.mybatisplus.generator.config.rules.DbType.MYSQL);
	        dataSourceConfig.setUrl("jdbc:mysql://47.93.46.51:3306/open_stage_server");
	        dataSourceConfig.setUsername("root");
	        dataSourceConfig.setPassword("admin");
	        dataSourceConfig.setDriverName("com.mysql.jdbc.Driver");
	
	        packageConfig.setParent(packageName);
	        packageConfig.setController("controller");
	        packageConfig.setEntity("entity");
	
//	         此处可以修改为您的表前缀；
//	         nochange  underline_to_camel；strategyConfig.setFieldNaming(NamingStrategy.underline_to_camel);.setNaming(NamingStrategy.remove_prefix_and_camel);
	        strategyConfig.setTablePrefix(tabPrefix);
	        strategyConfig.setCapitalMode(false);
	        strategyConfig.setDbColumnUnderline(true);
//	        strategyConfig.setFieldNaming(com.baomidou.mybatisplus.generator.config.rules.NamingStrategy.nochange);
	        strategyConfig.setNaming(com.baomidou.mybatisplus.generator.config.rules.NamingStrategy.underline_to_camel);
	        strategyConfig.setInclude(tableNames);//修改替换成你需要的表名，多个表名传数组
	        autoGenerator.setGlobalConfig(globalConfig);
	        autoGenerator.setDataSource(dataSourceConfig);
	        autoGenerator.setStrategy(strategyConfig);
	        autoGenerator.setPackageInfo(packageConfig);
	        autoGenerator.execute();
	
	
	    }
}
